מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator
|
|
- Georgina Dana Sims
- 6 years ago
- Views:
Transcription
1 מבוא למדעי המחשב 2017 תרגול 8 רשימה משורשרת כללית, Comparator
2 בתרגול היום. LinkedList בניית ההכללה מ- LinkIntList תרגול המבנה ושימושיו ממשקים: Comparator Sorted Linked List ל- LinkedList ע"י שימוש ב- Comparator
3 תזכורת: רשימה משורשרת רשימה המשורשרת היא אוסף איברים, בכל איבר מאוחסן מידע ברשימה. איבר ברשימה הינו מסוג Link וכן מצביע לאיבר הבא כל הרשימה נקראת LinkedList null Link Data Next
4 תזכורת: המחלקה Link public class Link { // fields private Object data; private Link next; // constructors public Link(Object data, Link next) { this.data = data; this.next = next; public Link(Object data) { this(data, null); public Link getnext() { public void setnext(link link) { public Object getdata() { public String tostring() { public boolean equals(object other) { 4
5 השיטה tostring של המחלקה Link public String tostring() { String output = ""; if (data!= null){ output = data.tostring(); return output; 5
6 תזכורת: המחלקה LinkedList public class LinkedList implements List{ // fields private Link first; private Link last; // constructors public LinkedList(){ first = null; last = null; // methods public boolean isempty() { public Object get(int index) { public String tostring() { public boolean equals(object other) { public int size() { public void add(object element) { public void add(int index,object element) { public boolean contains(object element) { 6
7 השיטה tostring של המחלקה LinkedList public String tostring() { String output = "<"; Link current = first; while (current!= null) { output = output + current.tostring()+ ","; current = current.getnext(); output = output.substring(0, output.length()-1) + ">"; return output; 7
8 דריסה )Overriding) ו"כלל הבצל" LinkedList Link Object first last Link Link Object data next Object Link String tostring() boolean equals(object other) String tostring() boolean equals(object other) : : : String tostring() String tostring() boolean equals(object other) boolean equals(object other) : : : 8
9 השיטה Link של המחלקה equals public boolean equals(object other) { boolean isequal = true; if (! (other instanceof Link)) isequal = false; else { Link otherlink = (Link) other; if (data == null){ if (otherlink.data!= null){ isequal = false; else{ isequal = data.equals(otherlink.data); return isequal; 9
10 LinkedList השיטה equals של המחלקה public boolean equals(object other) { boolean isequal = true; if (! (other instanceof LinkedList)) isequal = false; else { Link mycurrent = first; Link othercurrent = ((LinkedList) other).first; while (isequal & mycurrent!= null & othercurrent!= null) { isequal = mycurrent.equals(othercurrent); mycurrent = mycurrent.getnext(); othercurrent = othercurrent.getnext(); if (isequal) isequal = (mycurrent == null && othercurrent == null); return isequal; 10
11 הפסקה 11
12 המחלקה Student public class Student{ // fields private String name; private LinkedList grades; private int id; // constructors public Student(String studentname, int studentid) { name = studentname; id = studentid; grades = new LinkedList(); public void addgrade(integer grade) {grades.add(grade); public String getname() {return name public double calcavarage() { public String tostring() { public boolean equals(object other) { 12
13 ממשקים ממשק מייצג רעיון מופשט. הממשק )interface) הינו כלי למימוש עיקרון ההפרדה בין הכרזה למימוש. מבחינת המתכנת, ממשק הוא חוזה עבור הפונקציות שצריך למלא. ממשק קובע את הפונקציונאליות המשותפת לכל המחלקות המממשות אותו.
14 ממשקים הצהרה על ממשק: public interface <name> { <methods list> ממשקים מתארים שיטות )public( ללא מימושן. ממשקים אינם כוללים בנאים שכן אין דרך ליצר מופע )אובייקט( של ממשק אלא רק של מחלקה המממשת את הממשק. בדומה לשימוש במחלקות, המשתמש בממשק אינו צריך להכיר את פרטי המימוש של השיטות השונות.
15 הממשק Comparator public interface Comparator { public int compare(object obj1,object obj2); החוזה של השיטה אומר: יהיו a ו- b שני עצמים בני השוואה a > b compare(a,b) > 0 a.equals(b) compare(a,b) = 0 a < b compare(a,b) < 0 מימוש השיטה compare מגדיר את סוג ההשוואה המתבצעת 15
16 מימושים שונים לממשק Comparator public class StudentIDComparator implements Comparator { public int compare(object s1, Object s2) { if (! (s1 instanceof Student)!(s2 instanceof Student)) throw new RuntimeException(...); return ((Student) s1).getid()-((student) s2).getid(); public class StudentAverageComparator implements Comparator { public int compare(object s1, Object s2) { if (! (s1 instanceof Student)!(s2 instanceof Student)) throw new RuntimeException(...); double diff = ((Student) s2).calcavarage()-((student) s1). calcavarage(); if (diff > 0) return (int)(diff+1); return (int)diff;
17 הוספת findminvalue למחלקה LinkedList public Object findminvalue(comperator c){ Object minvalue = first.getdata(); Link currentlink = first; while (currentlink!= null){ if (c.compare(currentlink.getdata(), minvalue) < 0){ minvalue = currentlink.getdata() ; currentlink = currentlink.getnext(); return minvalue;
18 public Int id: static 1234 void main(string[] Object args) data: 92 Link first: { Student LinkedList grades: s1 = new Student( Dana,1234); Link next: s1.addgrade(92); Student s1.addgrade(56); String name: Yossi s1.addgrade(70); Int id: 5678 Link first: Student LinkedList s2 = grades: new Student( Yossi,5678); s2.addgrade(35); Student s2.addgrade(60); String name: Itay Student s3 = new Int id: Student( Itay,91011); Link first: s3.addgrade(100); LinkedList grades: s3.addgrade(98); Type Name Value Student Student Student Student String name: Dana s1 s2 s3 רשימה משורשרת של סטודנטים LinkedList Link Link Link Object data: 35 Link next: Object data: 56 Link next: LinkedList Link Link Object data: 100 Link next: Object data: 65 Link next: null Object data: 70 Link next: null LinkedList Link Link Object data: 98 Link next: null
19 רשימה משורשרת של סטודנטים public static void main(string[] Student args) {... String name: Dana LinkedList studentlist = new Int id: LinkedList(); studentlist.add(s1); LinkedList grades: studentlist.add(s2); studentlist.add(s3); Type Name Value Student Student Student LinkedList s1 s2 s3 studentlist Student String name: Yossi Int id: 5678 LinkedList grades:... Student String name: Itay Int id: LinkedList grades:... LinkedList Link Link Link Object data: Object data: Object data: Link first: Link next: Link next: Link next: null 19
20 החזרת המינימום ברשימה משורשרת public static void main(string[] args) { LinkedList studentlist = new LinkedList(); Comparator idcomp = new StudentIDComparator(); Comparator averagecomp = new StudentAverageComparator(); Object o1 = studentlist.findminvalue(idcomp); Object o2 = studentlist.findminvalue(averagecomp); Reference Type Name Instance Type value Comparator idcomp StudentIDComparator Comparator averagecomp StudentAverageComparator Object o1 Student Object o2 Student String name: Dana Int id: 1234 LinkedList grades: String name: Itay Int id: LinkedList grades:
21 השיטה tostring של המחלקה Student public String tostring() { return [ + Name: +name +, ID: + id +, Grades: + grades + ] ; public static void main(string[] args) { Student s = new Student( Dana,1234); s.addgrade(92); s.addgrade(56); s.addgrade(70); System.out.println(s); [Name: Dana, ID: 1234, Grades: <92, 56, 70>] 21
22 רשימה משורשרת של סטודנטים public static void main(string[] args) { Student s1 = new Student( Dana,1234); s1.addgrade(92); s1.addgrade(56); s1.addgrade(70); Student s2 = new Student( Yossi,5678); s2.addgrade(35); s2.addgrade(60); Student s3 = new Student( Itay,91011); s3.addgrade(100); s3.addgrade(98); LinkedList studentlist = new LinkedList(); studentlist.add(s1); studentlist.add(s2); studentlist.add(s3); System.out.println(studentList); <[Name: Dana, ID: 1234, Grades: <92, 56, 70>], [Name: Yossi, ID: 5678, Grades: <35, 60>], [Name: Itay, ID: 91011, Grades: <100, 98>]> 22
תזכורת: עץבינארי מבוא למדעי המחשב הרצאה 24: עצי חיפוש בינאריים
מבוא למדעי המחשב הרצאה 2: עצי חיפוש בינאריים תזכורת: עץבינארי בנוסףלרשימהמקושרת ומערך, הצגנומבנהנתונים קונקרטיחדש עץבינארי עץבינארימורכבמ: שורש תת-עץשמאלי תת-עץימני A B C D E F G 2 תזכורת: שורש ותתי-עצים
More informationתוכנה 1 סמסטר א' תשע"א
General Tips on Programming תוכנה 1 סמסטר א' תשע"א תרגול מס' 6 מנשקים, דיאגרמות וביטים * רובי בוים ומתי שמרת Write your code modularly top-down approach Compile + test functionality on the fly Start with
More informationמבוא למדעי המחשב תרגול 10 Comparator, Comparable, Binary Trees
מבוא למדעי המחשב 2018 תרגול 10 Comparator, Comparable, Binary Trees ראינו בהרצאה ממשקים Iterator Comparable Comparator עצים בינאריים BinaryNode,BinaryTree סריקות בתרגול היום ממשקים Comparable Comparator
More informationתוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב
תוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב Today Static vs. Dynamic binding Equals / hashcode String Immutability (maybe) 2 Static versus run-time
More informationתור שימושים בעולם התוכנה
מבוא למדעי המחשב הרצאה : Queue, Iterator & Iterable תור מבנה נתונים אבסטרקטי תור שימושים בעולם התוכנה השימושים של תורים בעולם התוכנה מזכירים מאוד תורים במציאות: )VoIP( )YouTube( מקלדת שידור סרט באינטרנט
More informationחומר עזר לבחינה במבוא למדעי המחשב // Indicates whether some other object is "equal to" // this one. boolean equals(object other)
חומר עזר לבחינה במבוא למדעי המחשב 202-1-1011 שיטות במחלקה Object // Indicates whether some other object is "equal to" // this one. boolean equals(object other) // Returns a string representation of the
More informationמבוא למדעי המחשב 2018 תרגול 7
מבוא למדעי המחשב 2018 תרגול 7 רשימות משורשרות, רקורסיית זנב 1 ראינו בהרצאה רשימות משורשרות רקורסיית זנב 2 בתרגול היום רשימות משורשרות עוד שיטות מחלקה רקורסיית זנב היפוך מחרוזות, חיפוש בינארי 3 רשימות משורשרות
More informationתרגול 6 רקורסיה ותכנות מונחה עצמים
מבוא למדעי המחשב 2017 תרגול 6 רקורסיה ותכנות מונחה עצמים מבוא למדעי המחשב 1 ראינו בהרצאה רקורסיה תכנות מונחה עצמים: מחלקה ואובייקט שדות, בנאים ושיטות מימוש מערך דינאמי של ראשוניים בתרגול היום רקורסיה הדפסת
More informationתוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes
תוכנה 1 תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes class Outer { static class NestedButNotInner {... class Inner {... מחלקות מקוננות NESTED CLASSES 2 מחלקה מקוננת Class) )Nested
More informationתרגול 7 רשימות משורשרות, רקורסיית
מבוא למדעי המחשב 2018 תרגול 7 רשימות משורשרות, רקורסיית זנב 1 ראינו בהרצאה רשימות משורשרות רקורסיית זנב 2 בתרגול היום רשימות משורשרות עוד שיטות מחלקה רקורסיית זנב היפוך מחרוזות, חיפוש בינארי 3 רשימות משורשרות
More informationמערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1
מערכים שעור מס. 4 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 למה מערכים? ברצוננו לאחסן בתוכנית ציוני בחינה כדי לחשב את ממוצע הציונים וסטיית התקן. נניח ש 30 סטודנטים לקחו
More informationמשתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1
משתנים שעור מס. 2 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 תפקיד המשתנים הצהרה על משתנה השמת ערך במשתנה int a, b, c; a = 1234; b = 99; c = a + b; משתנים מאפשרים לנו לשמור
More informationIntroduction to Computer Science II (CSI 1101) Midterm Examination
Identification Student name: Introduction to Computer Science II (CSI 1101) Midterm Examination Instructor: Marcel Turcotte February 2003, duration: 2 hours Student number: Section: Instructions 1. This
More informationתוכנה 1 תרגול מספר 13
1 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 2 ו- HASHCODE EQUALS 3 תזכורת: המחלקה Object package
More informationתוכנה 1 תרגול מספר 13
1 2 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( ו- HASHCODE EQUALS חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 3 4 package java.lang; תזכורת: המחלקה
More informationCS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12
CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can
More informationתוכנה 1 * לא בהכרח בסדר הזה
תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות המימוש שלהן. )חתימות( ללא קוד אשר
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More information1. ArrayList and Iterator in Java
1. ArrayList and Iterator in Java Inserting elements between existing elements of an ArrayList or Vector is an inefficient operation- all element after the new one must be moved out of the way which could
More informationChapter 5 - A Simple Dynamic Linked List (Holding Strings)
Chapter 5 - A Simple Dynamic Linked List (Holding Strings) Very Simple Link Class Holding String Data and Reference to Next Link (Version 1) public class Link{ private String data; private Link next; public
More informationInterfaces, collections and comparisons
תכנות מונחה עצמים תרגול מספר 4 Interfaces, collections and comparisons Interfaces Overview Overview O Interface defines behavior. Overview O Interface defines behavior. O The interface includes: O Name
More informationמבוא למדעי המחשב תרגול 10 הממשקים Iterator, Iterable Binary trees
מבוא למדעי המחשב 2017 תרגול 10 הממשקים Iterator, Iterable Binary trees בתרגול היום ממשקים: Iterator Filter DynamicArrayFilterIterator עצים בינאריים. תזכורת: Iterator מידע ונתונים )data( הדרושים לתכנית
More informationמבני נתונים תכנות מונחה עצמים מבני נתונים. מחלקות אבסטרקטיות חבילות packages סיכום הרשאות גישה wrappers ADT מערך דינמי מחסנית
מבני נתונים 1 תכנות מונחה עצמים מחלקות אבסטרקטיות חבילות packages סיכום הרשאות גישה wrappers מבני נתונים ADT מערך דינמי מחסנית 2 1 מבני נתונים תור - Queue Iterators רשימות מקושרות "רגילות" 3 מבנה נתונים
More informationC12a: The Object Superclass and Selected Methods
CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming
More informationIMPLEMENTING BINARY TREES
IMPLEMENTING BINARY TREES Chapter 6 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F 1 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F A Binary
More informationLinked Lists. Chapter 12.3 in Savitch
Linked Lists Chapter 12.3 in Savitch Preliminaries n Arrays are not always the optimal data structure: q An array has fixed size needs to be copied to expand its capacity q Adding in the middle of an array
More informationממשק משתמש גרפי בעזרת SWT
ממשק משתמש גרפי בעזרת SWT מה עושים היום? קריאת Stack Trace של חריגה hashcode ו- equals ממשק משתמש גרפי תוכנה 1 בשפת Java 2 1 Interpreting Stack Trace of an Exception Exception in thread "main" java.lang.outofmemoryerror:
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Exam Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need to include
More informationתוכנה 1 * לא בהכרח בסדר הזה
תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות המימוש שלהן. )חתימות( ללא קוד אשר
More informationהנכות 1 םוכיס לוגרת 14 1
תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers
More information(Constructor) public A (int n){ for (int i = 0; i < n; i++) { new A(i); } System.out.println("*"); }
!!#!#"! (Constructor) A public A (int n){ for (int i = 0; i < n; i++) { new A(i); System.out.println("*"); % 1. new A(0); 2. new A(1); 3. new A(2); 4. new A(3); & ) n 5. A a = new A(n);! '#" +"()* " %floating
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified
More informationתוכנה 1 * לא בהכרח בסדר הזה
תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים - תזכורת מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות )חתימות(. מימוש דיפולטיבי
More informationCS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 There are 7 problems on the exam, with 50 points total available. There are 8 pages to the exam (4 pages double-sided),
More informationJava Collections. Wrapper classes. Wrapper classes
Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being
More informationJava Collections. Engi Hafez Seliem
Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being
More informationTopic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1
Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing
More information: Advanced Programming Final Exam Summer 2008 June 27, 2008
15-111 : Advanced Programming Final Exam Summer 2008 June 27, 2008 Name: Andrew ID: Answer the questions in the space provided following each question. We must be able to clearly understand your answer.
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationDM537 Object-Oriented Programming. Peter Schneider-Kamp.
DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! RECURSION (REVISITED) 2 Recursion (Revisited) recursive function = a function that calls
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationהנכות 1 םוכיס לוגרת 13 1
תוכנה 1 סיכום תרגול 13 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers
More informationJava Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering
Readings and References Java Collections References» "Collections", Java tutorial» http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Winter 2003 Software Engineering http://www.cs.washington.edu/education/courses/403/03wi/
More informationמבוא לתכנות ב- JAVA תרגול 7
מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה
More informationInheritance (Part 5) Odds and ends
Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ RECURSION (REVISITED) 2 Recursion (Revisited)
More informationCS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction
More information1) Consider the following code segment, applied to list, an ArrayList of Integer values.
Advanced Computer Science Unit 7 Review Part I: Multiple Choice (12 questions / 4 points each) 1) What is the difference between a regular instance field and a static instance field? 2) What is the difference
More informationPolymorphism. return a.doublevalue() + b.doublevalue();
Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces
More informationCMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.
CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object
More informationPractical Session - Heap
Practical Session - Heap Heap Heap Maximum-Heap Minimum-Heap Heap-Array A binary heap can be considered as a complete binary tree, (the last level is full from the left to a certain point). For each node
More informationData abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003
Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation
More informationCMPSCI 187 Midterm 1 (Feb 17, 2016)
CMPSCI 187 Midterm 1 (Feb 17, 2016) Instructions: This is a closed book, closed notes exam. You have 120 minutes to complete the exam. The exam has 10 pages printed on double sides. Be sure to check both
More informationEXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction
More informationLinkedList Implementation Mini-project intro
LinkedList Implementation Mini-project intro Turn in your written problems Mini-project Partner Survey: Do it by 4:00 today Reminder: Exam #2 is this Thursday In order to reduce time pressure, you optionally
More informationThe Java Collections Framework and Lists in Java Parts 1 & 2
The Java Collections Framework and Lists in Java Parts 1 & 2 Chapter 9 Chapter 6 (6.1-6.2.2) CS 2334 University of Oklahoma Brian F. Veale Groups of Data Data are very important to Software Engineering
More informationpublic class B { private int f = 0; public static void main(string[] args) { B b1 = new B(); B b2 = new B(); Object b3 = b1;
main /***/ public class B { private int f = 0; public static void main(string[] args) { B b1 = new B(); B b2 = new B(); Object b3 = b1; System.out.println(/***/); @Override public boolean equals(object
More information141214 20219031 1 Object-Oriented Programming concepts Object-oriented programming ( תכנות מונחה עצמים ) involves programming using objects An object ) (עצם represents an entity in the real world that
More informationחומר עזר לבחינה מבוא למדעי המחשב
שיטות במחלקה Object // Indicates whether some other object is "equal to" // this one. boolean equals(object other) // Returns a string representation of the object. String tostring() // Returns the length
More informationPage 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:
This pledged exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not
More informationANSWER KEY. Study Guide. Completely fill in the box corresponding to your answer choice for each question.
CS 1331 Final Exam Study Guide ANSWER KEY Completely fill in the box corresponding to your answer choice for each question. 1. [ B ] [ C ] [ D ] 2. [ B ] [ C ] [ D ] 3. [ B ] [ C ] [ D ] 4. [ B ] [ C ]
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationתרגול 12. Standard Template Library כתיבת אלגוריתמים גנריים מצביעים חכמים
תרגול 12 Standard Template Library כתיבת אלגוריתמים גנריים מצביעים חכמים ספרית התבניות הסטנדרטית קיימת בכל מימוש של ++C מכילה אוספים (Containers) ואלגוריתמים. משתמשת בתבניות :(templates) אוספי הנתונים
More informationJava Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering
Readings and References Java Collections "Collections", Java tutorial http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Spring 2004 Software Engineering http://www.cs.washington.edu/education/courses/403/04sp/
More informationThe class Object. Lecture CS1122 Summer 2008
The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship
More informationIntroduction to Computer Science II (CSI 1101)
Introduction to Computer Science II (CSI 1101) Professor: M. Turcotte February 2002, duration: 75 minutes Identification Student name: last name: Section: Student number: initials: Signature: Instructions
More informationלתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions
מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 >>g = [89 91 80 98]; >>p
More informationInstance Method Development Demo
Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationDM503 Programming B. Peter Schneider-Kamp.
DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! ABSTRACT DATATYPE FOR LISTS 2 List ADT: Specification data are all integers, here represented as primitive
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 16 Mar 2017 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationPrelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer
Prelim 1 SOLUTION CS 2110, September 29, 2016, 7:30 PM 0 1 2 3 4 5 Total Question Name Loop invariants Recursion OO Short answer Exception handling Max 1 15 15 25 34 10 100 Score Grader 0. Name (1 point)
More informationCS 1331 Exam 1 ANSWER KEY
CS 1331 Exam 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in
More informationמבוא למדעי המחשב השפעת השינוי על סטודנט הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות אם ברצוננו ששכר הלימוד לא יעלה על 2500.
public class { private static final int COURSE_PRICE = 1000; private String nae; private int id; private int nuofcourses; מבוא למדעי המחשב הרצאה 18 פולימורפיזם ומחלקות אבסטרקטיות תזכורת public (int id,
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More information16. Give a detailed algorithm for making a peanut butter and jelly sandwich.
COSC120FinalExamReview2010 1. NamethetwotheoreticalmachinesthatCharlesBabbagedeveloped. 2. WhatwastheAntikytheraDevice? 3. Givethecodetodeclareanintegervariablecalledxandthenassignitthe number10. 4. Givethecodetoprintout
More informationPage 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
Page 1 of 16 HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2005 FINAL EXAMINATION 9am to 12noon, 19 DECEMBER 2005 Instructor: Alan McLeod If
More informationספרית התבניות הסטנדרטית (STL) כתיבת אלגוריתמים גנריים מצביעים חכמים. .vector. list iterator נכיר תחילה את האוסף הפשוט ביותר בספריה
ספרית התבניות הסטנדרטית (STL) כתיבת אלגוריתמים גנריים מצביעים חכמים vector list iterator 2 קיימת בכל מימוש של ++C מכילה אוספים (Containers) ואלגוריתמים נכיר תחילה את האוסף הפשוט ביותר בספריה.vector מערך
More informationלתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions
מבוא לתיכנות עם MATLAB 23427 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 203 Based on slides of Dr. Eran Eden, Weizmann 2008 ביטויים לוגיים דוגמא: תקינות
More informationImplementing a List in Java. CSE 143 Java. Just an Illusion? List Interface (review) Using an Array to Implement a List.
Implementing a List in Java CSE 143 Java List Implementation Using Arrays Reading: Ch. 13 Two implementation approaches are most commonly used for simple lists: Arrays Linked list Java Interface List concrete
More informationLinked List. ape hen dog cat fox. tail. head. count 5
Linked Lists Linked List L tail head count 5 ape hen dog cat fox Collection of nodes with a linear ordering Has pointers to the beginning and end nodes Each node points to the next node Final node points
More informationTema 5. Ejemplo de Lista Genérica
Tema 5. Ejemplo de Lista Genérica File: prlista/lista.java package prlista; import java.util.arrays; import java.util.stringjoiner; import java.util.nosuchelementexception; public class Lista { private
More informationTask 2 What is printed out when the code is executed?
Task 1 What is printed out when the code is executed? public class Class1 { public static void main(string[] args) { int array[] = {14,5,7; for (int counter1 = 0; counter1 < array.length; counter1++) {
More informationChapter 13. Inheritance and Polymorphism. CS 180 Sunil Prabhakar Department of Computer Science Purdue University
Chapter 13 Inheritance and Polymorphism CS 180 Sunil Prabhakar Department of Computer Science Purdue University Introduction Inheritance and polymorphism are key concepts of Object Oriented Programming.
More informationLinked Lists. Linked List Nodes. Walls and Mirrors Chapter 5 10/25/12. A linked list is a collection of Nodes: item next -3.
Linked Lists Walls and Mirrors Chapter 5 Linked List Nodes public class Node { private int item; private Node next; public Node(int item) { this(item,null); public Node(int item, Node next) { setitem(item);
More informationIntroduction to Computing II (ITI 1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More informationSSE3052: Embedded Systems Practice
SSE3052: Embedded Systems Practice Minwoo Ahn minwoo.ahn@csl.skku.edu Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3052: Embedded Systems Practice, Spring 2018, Jinkyu Jeong
More informationסעיף ב )11 נקודות( public synchronized void advance(staircase staircase) throws InterruptedException staircase!
גיליון תשובות מספר נבחן: 03( שאלה 1 סעיף א )10 @INV: 0
More informationPASS4TEST IT 인증시험덤프전문사이트
PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from
More informationCS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016
General instructions: CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016 Please wait to open this exam booklet until you are told to do so. This examination booklet has 13 pages.
More informationCOMP200 - Object Oriented Programming: Test One Duration - 60 minutes
COMP200 - Object Oriented Programming: Test One Duration - 60 minutes Study the following class and answer the questions that follow: package shapes3d; public class Circular3DShape { private double radius;
More informationCSE143 Summer 2008 Final Exam Part B KEY August 22, 2008
CSE143 Summer 2008 Final Exam Part B KEY August 22, 2008 Name : Section (eg. AA) : TA : This is an open-book/open-note exam. Space is provided for your answers. Use the backs of pages if necessary. The
More informationCONTAİNERS COLLECTİONS
CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping
More informationCS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes
CS/ENGRD 2110 SPRING 2019 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due Thursday night (14 February) Go back to Lecture 6 & discuss method
More informationשאלה 1 מהו הפלט של התוכנית הבאה:
תרגול חזרה שאלה 1 מהו הפלט של התוכנית הבאה: public sttic int wht(int n) { int i; int sum=0; if(n == 0) return 1; for (i=0; i
More informationתרגול 9 מחלקות ואובייקטים
תרגול 9 מחלקות ואובייקטים 1 1. Complex Numbers Design class Complex, representing an immutable complex number. Use this class to read two complex numbers from the user, print their sum and product, and
More information- MEAN Stack חזרה. MongoDB - as the database Express - as the web framework AngularJS - as the frontend framework NodeJS- as the server platform
הדר פיקאלי תשע"ו - 2016 - MEAN Stack חזרה בניית web applications כרוכה בשימוש בטכנולוגיות וכלים שונים, להתמודדות עם: מסד נתונים, פעולות בצד השרת, טיפול בצד הלקוח והצגה של הנתונים. מהו?MEAN "MEAN is a fullstack
More informationCSCD 326 Data Structures I Stacks
CSCD 326 Data Structures I Stacks 1 Stack Interface public interface StackInterface { public boolean isempty(); // Determines whether the stack is empty. // Precondition: None. // Postcondition: Returns
More information